/**   
 * @Title: DiagramController.java 
 * @Package org.playgod1984.du.ddesign.controller 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author playgod playgod1984@163.com  
 * @date 2014年10月27日 下午5:02:22 
 * @version V1.0   
 */
package org.playgod1984.du.ddesign.controller;

import java.util.Map;

import org.playgod1984.du.base.ApplicationController;
import org.playgod1984.du.ddesign.model.Diagram;
import org.playgod1984.du.ddesign.model.Project;
import org.playgod1984.du.ddesign.validator.DiagramValidator;

import com.jfinal.aop.Before;

/** 
 * @ClassName: DiagramController 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author playgod playgod1984@163.com 
 * @date 2014年10月27日 下午5:02:22 
 *  
 */
@SuppressWarnings("all")
public class DiagramController extends ApplicationController {
	/**
	 * @Title: g2add
	 * @author:playgod playgod1984@163.com 
	 * @Description: 添加 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void g2add(){
		setAttr("screen", "A");// add
		String proid = getPara("projectid");
		Project pro = Project.dao.findById(proid);
		setAttr("projectid", proid);
		setAttr("projectname", pro.getStr("projectname"));
		render("/WEB-INF/views/ddesign/diagram/diagram_edit.html");
	}
	
	public void g2edit(){		
		Diagram diag = Diagram.dao.findById(getPara("diagramid"));
		setAttr("screen", "E");// edit
		setAttr("diag", diag);
		setAttr("projectid", diag.getStr("projectid"));
		Project pro = Project.dao.findById(diag.getStr("projectid"));
		setAttr("projectname", pro.getStr("projectname"));
		render("/WEB-INF/views/ddesign/diagram/diagram_edit.html");
	}
	/**
	 * @Title: save
	 * @author:playgod playgod1984@163.com 
	 * @Description: TODO(这里用一句话描述这个方法的作用) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	@Before(DiagramValidator.class)
	public void save(){
		Map params = getParamsMap();
		if(Diagram.dao.save(params)){
			renderJson(RES_SUCCESS);
		}else{
			renderJson(RES_FAILED);
		}
	}
	/**
	 * @Title: delete
	 * @author:playgod playgod1984@163.com 
	 * @Description: Delete Records
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void delete(){
		Map params = getParamsMap();
		int delRes = Diagram.dao.deleteRows(params);
		renderJson(delRes);
	}
}
